/*! \file VertexFormat.inl
 *	\brief 
 *
 *	created:	2009/11/25
 *	created:	25:11:2009   17:09
 *	filename: 	o:\gag-engine\libs\gd\VertexFormat.inl
 *	file path:	o:\gag-engine\libs\gd
 *	file base:	VertexFormat
 *	file ext:	inl
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
namespace tt{
namespace gd{

const UInt VF_POSITION_SIZE = 3 * sizeof(Float);
const UInt VF_NORMAL_SIZE = 3 * sizeof(Float);
const UInt VF_COLOR_SIZE = 3 * sizeof(Float);

inline
VertexFormat::VertexFormat()
: m_vertexFormat(0)
{
}

inline
VertexFormat& VertexFormat::addPosition()
{
	addFlag(F_POSITION);
	return *this;
}

inline
bool VertexFormat::hasPosition() const
{
	return hasFlag(F_POSITION);
}

inline
VertexFormat& VertexFormat::addNormal()
{
	addFlag(F_NORMAL);
	return *this;
}

inline
bool VertexFormat::hasNormal() const
{
	return hasFlag(F_NORMAL);
}

inline
VertexFormat& VertexFormat::addColor()
{
	addFlag(F_COLOR);
	return *this;
}

inline
bool VertexFormat::hasColor() const
{
	return hasFlag(F_COLOR);
}

inline
UInt VertexFormat::vertexSize() const
{
	UInt size = 0;
	if( hasPosition() )
		size += VF_POSITION_SIZE;
	if( hasNormal() )
		size += VF_NORMAL_SIZE;
	if( hasColor() )
		size += VF_COLOR_SIZE;
	return size;
}

inline
UInt VertexFormat::positionOffset() const
{
	//ttAssert(hasPosition());
	return 0;
}

inline
UInt VertexFormat::normalOffset() const
{
	//ttAssert(hasNormal());

	UInt offset = 0;
	if (hasPosition())
		offset += VF_POSITION_SIZE;
	return offset;
}

inline
UInt VertexFormat::colorOffset() const
{
	//ttAssert(hasColor());

	UInt offset = 0;
	if (hasPosition())
		offset += VF_POSITION_SIZE;
	if (hasNormal())
		offset += VF_NORMAL_SIZE;
	return offset;
}

//////////////////////////////////////////////////////////////////////////
inline
void VertexFormat::addFlag(UInt flag)
{
	m_vertexFormat |= flag;
}

inline
bool VertexFormat::hasFlag(UInt flag) const
{
	return (m_vertexFormat & flag) == flag;
}

} //namespace gd
} //namespace tt
